<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>角色管理</title>
<link rel="stylesheet" type="text/css" href="${request.contextPath}/resources/css/zTreeStyle.css" media="screen" />

<script type="text/javascript" src="${request.contextPath}/resources/js/jquery.ztree.all-3.5.min.js"></script>

<script>

//查询菜单信息	
var searchRoleData =function()
{
	$.ajax({
		url:'${request.contextPath}/role/getAllRole.htm',
		type:'post',
		dataType:'html',
		async:'false',
		cache:false,
		processData:true,
		success:function(html)
		{
			$('#dataDiv').html(html);
		}
	});
}

//打开添加角色的模态框
var preAddRole= function()
{

	$.ajax({
		url:'${request.contextPath}/role/preAddRole.htm',
		type:'post',
		dataType:'html',
		async:'false',
		cache:false,
		processData:true,
		success:function(html)
		{
			$('#windowDiv').html(html);
			$('#addModal').modal();
		}
	});
	
}

//添加角色
var addRole = function()
{
	var menuIds='';
	$.each(treeObj.getCheckedNodes(true),function(n,value){
		if(n==0)
		{
			menuIds += value.id;
		}
		else
		{
			menuIds += ','+value.id;
		}
		
	});
	$.ajax({
		url:'${request.contextPath}/role/addRole.htm',
		type:'post',
		dataType:'json',
		async:'false',
		cache:false,
		processData:true,
		data:{
			'menuIds':menuIds,
			'roleName':$('#roleName').val()
		},
		success:function(data)
		{
			
			alert(data.msg);
			if(data.success==1)
			{
				$('#addModal').modal('hide');
				searchRoleData();
			}
		}
	});
	
	
}

//修改前的展示页面
var preModifyRoleByRoleId = function(rid)
{
	$.ajax({
		url:'${request.contextPath}/role/preModifyRole.htm',
		type:'post',
		dataType:'html',
		async:'false',
		cache:false,
		processData:true,
		data:{
			'rid':rid
		},
		success:function(html)
		{
			$('#windowDiv').html(html);
			$('#editModal').modal();
		}
	});
}

//删除用户
var deleteRole = function(rid)
{
	if(!confirm('确定删除该用户么！'))
	{
		return false;
	}
	$.ajax({
		url:'${request.contextPath}/role/deleteRole.htm',
		type:'post',
		dataType:'json',
		data:{
			'roleId':rid
		},
		async:'false',
		cache:false,
		processData:true,
		success:function(data)
		{
			alert(data.msg);
			searchRoleData();
		}
	});
}

//修改角色
var saveRoleFn = function()
{
	var menuIds='';
	$.each(treeObj.getCheckedNodes(true),function(n,value){
		if(n==0)
		{
			menuIds += value.id;
		}
		else
		{
			menuIds += ','+value.id;
		}
		
	});
	$.ajax({
		url:'${request.contextPath}/role/modifyRole.htm',
		type:'post',
		dataType:'json',
		async:'false',
		cache:false,
		processData:true,
		data:{
			'roleId':$('#roleId').val(),
			'menuIds':menuIds,
			'roleName':$('#roleName').val()
		},
		success:function(data)
		{
			
			alert(data.msg);
			if(data.success==1)
			{
				$('#addModal').modal('hide');
				searchRoleData();
			}
		}
	});
}

searchRoleData();
</script>
</head>
<body style="overflow:hidden">
<span class="cp_title">角色管理</span>
<br/>
<br/>
<div id="dataDiv">
</div>

<div id="windowDiv">
</div>



</body>
</html>
